package net.lab1024.sa.admin.module.system.user.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

import net.lab1024.sa.admin.module.system.type.domain.TypeEntity;
import net.lab1024.sa.admin.module.system.type.service.TypeService;
import net.lab1024.sa.admin.module.system.user.domain.JdyVO;
import net.lab1024.sa.admin.module.system.user.domain.UserVO;
import net.lab1024.sa.admin.module.system.user.domain.form.UserAddForm;
import net.lab1024.sa.admin.module.system.user.domain.form.UserQueryForm;
import net.lab1024.sa.admin.module.system.user.domain.form.UserUpdateForm;
import net.lab1024.sa.admin.module.system.user.service.UserService;
import net.lab1024.sa.base.common.controller.SupportBaseController;
import net.lab1024.sa.base.common.domain.PageResult;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.constant.SwaggerTagConst;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 配置
 *
 * @Author 1024创新实验室-主任: 卓大
 * @Date 2022-03-14 20:46:27
 
 
  * @Copyright  cpedu
 */
@Tag(name = SwaggerTagConst.Support.CONFIG)
@RestController
public class UserController extends SupportBaseController {

    @Resource
    private UserService userService;
    @Resource
    private TypeService typeService;

    @Operation(summary = "分页商品信息")
    @PostMapping("/user/query")
    @SaCheckPermission("support:user:query")
    public ResponseDTO<PageResult<UserVO>> queryShopPage(@RequestBody @Valid UserQueryForm queryForm) {
        ResponseDTO<PageResult<UserVO>> pageResult = userService.queryUser(queryForm);
        return userService.queryUser(queryForm);
    }
    @Operation(summary = "分页商品信息")
    @PostMapping("/user/queryJdy")
    @SaCheckPermission("support:user:query")
    public ResponseDTO<PageResult<JdyVO>> queryJdyPage(@RequestBody @Valid UserQueryForm queryForm) {
        ResponseDTO<PageResult<JdyVO>> pageResult = userService.queryjdy(queryForm);
        return pageResult;
    }
    @Operation(summary = "获取专业列表")
    @GetMapping("/user/queryType")
    @SaCheckPermission("support:user:query")
    public ResponseDTO<List<TypeEntity>> queryShopPage(@RequestParam(defaultValue = "pro_major") String key) {
        return typeService.getTypeList(key);
    }

    @Operation(summary = "添加商品信息  ")
    @PostMapping("/user/add")
    @SaCheckPermission("support:user:add")
    public ResponseDTO<String> addShop(@RequestBody @Valid UserAddForm userAddForm) {
        return userService.add(userAddForm);
    }

    @Operation(summary = "修改商品参数  ")
    @PostMapping("/user/update")
    @SaCheckPermission("support:user:update")
    public ResponseDTO<String> updateSp(@RequestBody @Valid UserUpdateForm updateForm) {
        return userService.updateUser(updateForm);
    }
    @Operation(summary = "删除商品信息  ")
    @PostMapping("/user/delete")
    @SaCheckPermission("support:user:delete")
    public ResponseDTO<String> deleteSp(@RequestBody @Valid UserUpdateForm updateForm) {
        return userService.deleteUser(updateForm);
    }
    @Operation(summary = "修改商品参数  ")
    @GetMapping("/user/queryById/{userId}")
//    @SaCheckPermission("support:user:query")
    public ResponseDTO<UserVO> queryById(@PathVariable Integer userId) {
        return userService.queryById(userId);
    }
}
